Skip to content

feat(query): implements "Beta - Activity Log Alert For Service Health Not Configured"#7821

Merged
cx-andre-pereira merged 18 commits into
masterfrom
AST-116647_40_6.1.2.11_ensure_activity_log_alert_for_service_health
Dec 9, 2025
Merged

feat(query): implements "Beta - Activity Log Alert For Service Health Not Configured"#7821
cx-andre-pereira merged 18 commits into
masterfrom
AST-116647_40_6.1.2.11_ensure_activity_log_alert_for_service_health

Conversation

@cx-andre-pereira

@cx-andre-pereira cx-andre-pereira commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

Reason for Proposed Changes

  • Currently there is no query to ensure that there is a "azurerm_monitor_activity_log_alert" resource configured to capture "Service Health" events.

  • Quoting CIS_Microsoft_Azure_Foundations_Benchmark_v5.0.0 page 267: "Monitoring for Service Health events provides insight into service issues, planned maintenance, security advisories, and other changes that may affect the Azure services and regions in use."

  • Through the CIS benchmark we can also determine that detecting the target configuration boils down to checking 4 conditions :

    • The "scopes" field should target a subscription.
    • The category field should be set to "ServiceHealth"
    • In the "events" array, "Incident" should be included
    • Finally it must be ensured that the "action_group_id" field is set (inside an "action" block).
  • It is expected that all "subscriptions" are associated in this manner, the data block "azurerm_subscription" allows defining these subscriptions, and so the query should iteratively check all associated alert logs for each subscription.

Proposed Changes

  • Implemented the missing query.

  • The query will start by collecting all log alert type resources as well as all subscriptions defined through data azurerm_subscription blocks.

  • Then, for each subscription, the log alerts are scrubbed to search for at least one that fulfills requisites 2, 3 and 4 and references the specific subscription the auxiliary function "at_least_one_valid_log_alert" got called for.

  • The query will trigger differently depending on the log_alerts found, with the following priority :

    • Flag for the "action_group_id" not being set
    • Flag if the "events" array does not include "Incident"
    • Flag if the "category" is set to a value that is not "ServiceHealth"
    • Flag the subscription itself if there is not a single log alert resource associated with it.
  • These priorities are demonstrated through the positive4 and positive5 tests and their results.

I submit this contribution under the Apache-2.0 license.

@github-actions github-actions Bot added feature New feature query New query feature labels Nov 5, 2025
@github-actions

github-actions Bot commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.17

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 47
Queries failed to execute placeholder 0
Execution time placeholder 0

@github-actions github-actions Bot added terraform Terraform query azure PR related with Azure Cloud labels Nov 5, 2025
@cx-andre-pereira cx-andre-pereira marked this pull request as ready for review November 5, 2025 15:18
@cx-andre-pereira cx-andre-pereira requested a review from a team as a code owner November 5, 2025 15:18
@cx-andre-pereira cx-andre-pereira changed the title feat(query): implements "Beta - Activity Log Alert For Service Health" feat(query): implements "Beta - Activity Log Alert For Service Health Not Configured" Nov 6, 2025

@cx-eduardo-semanas cx-eduardo-semanas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cx-eduardo-semanas cx-eduardo-semanas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cx-eduardo-semanas cx-eduardo-semanas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cx-andre-pereira cx-andre-pereira merged commit 19c5cf4 into master Dec 9, 2025
29 checks passed
@cx-andre-pereira cx-andre-pereira deleted the AST-116647_40_6.1.2.11_ensure_activity_log_alert_for_service_health branch December 9, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure PR related with Azure Cloud feature New feature query New query feature terraform Terraform query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants